<template>
  <!-- 多语言加载状态 -->
  <div class="language-loading" v-if="!isLanguageReady">
    <div class="loading-content">
      <div class="loading-spinner"></div>
      <p>loading...</p>
    </div>
  </div>
  
  <div class="app-layout" v-else>
    <header class="app-header">
      <div class="container">
        <div class="header-content">
          <div class="logo">
            <img src="@/assets/images/logo.png" alt="Logo" />
            <img src="@/assets/images/logo_new.png" alt="Logo" />
          </div> 
          <nav class="desktop-nav">
            <!-- 桌面端菜单 -->
            <ul class="nav-links">
              <li><router-link to="/chat/home">{{ languageStore.t('home') }}</router-link></li>
              <li><router-link to="/chat/about">{{ languageStore.t('about_us') }}</router-link></li>
            </ul>
          </nav>
          
          <!-- 语言切换 -->
          <div class="language-switcher">
            <div class="selected-lang" @click="toggleLangMenu">
              <span>{{ currentLangName }}</span>
              <i class="lang-arrow">▼</i>
            </div>
            <div class="lang-menu" v-show="showLangMenu">
              <div 
                v-for="lang in supportedLangs" 
                :key="lang.code" 
                class="lang-item" 
                :class="{ 'active': currentLang === lang.code }"
                @click="switchLanguage(lang.code)"
              >
                {{ lang.name }}
              </div>
            </div>
          </div>
          
          <!-- 用户区域 - 移动端或未登录时显示 -->
          <div class="user-area" v-if="isMobile || !isLoggedIn">
            <template v-if="isLoggedIn">
              <div class="user-dropdown" @click="toggleUserMenu">
                <span class="username">{{ userInfo.nickname || userInfo.phone }}</span>
              </div>
              <!-- 用户菜单 -->
              <div class="user-menu" v-show="showUserMenu">
                <div class="user-menu-item" @click="goToUserCenter">{{ languageStore.t('personal_info') }}</div>
                <div class="user-menu-item" @click="goToRecharge">{{ languageStore.t('recharge') }}</div>
                <div class="user-menu-item" @click="handleLogout">{{ languageStore.t('logout') }}</div>
              </div>
            </template>
            <button v-else class="login-btn" @click="modalStore.openLoginModal">{{ languageStore.t('login_register') }}</button>
          </div>
          
          <div class="mobile-menu-toggle" @click="toggleMobileMenu">
            <span></span>
            <span></span>
            <span></span>
          </div>
        </div>
      </div>
    </header>

    <!-- 移动端抽屉菜单 -->
    <el-drawer
      v-model="isMobileMenuOpen"
      :with-header="false"
      direction="ltr"
      size="80%"
      :before-close="closeMobileMenu"
      custom-class="mobile-drawer"
    >
      <!-- 用户信息卡片（已登录状态） -->
      <div class="mobile-user-profile" v-if="isLoggedIn">
        <div class="user-profile-card">
          <div class="user-avatar-section">
            <div class="user-avatar-container" v-if="userInfo.avatar">
              <div class="user-avatar-img">
                <img :src="userInfo.avatar" alt="用户头像" @error="handleAvatarError" />
              </div>
            </div>
            <div class="user-basic-info">
              <h3 class="username">{{ userInfo.nickname || userInfo.phone }}</h3>
              <p class="user-status" v-if="userStore.getPremiumStatus">
                <span class="premium-icon">👑</span>
                <span>{{ languageStore.t('premium_member') }}</span>
              </p>
              <p class="user-phone" v-if="userInfo.phone">{{ userInfo.phone }}</p>
            </div>
          </div>
        </div>
        
        <!-- 快捷操作按钮 -->
        <div class="quick-actions">
          <button class="action-btn" @click="goToUserCenter(); closeMobileMenu();">
            <i class="icon">👤</i>
            {{ languageStore.t('personal_info') }}
          </button>
          <button class="action-btn" @click="goToRecharge(); closeMobileMenu();">
            <i class="icon">💳</i>
            {{ languageStore.t('recharge') }}
          </button>
          <button class="action-btn logout-btn" @click="handleLogout(); closeMobileMenu();">
            <i class="icon">🚪</i>
            {{ languageStore.t('logout') }}
          </button>
        </div>
      </div>
      
      <!-- 未登录状态显示登录按钮 -->
      <div class="mobile-login-section" v-else>
        <el-button type="primary" size="large" class="mobile-login-btn" @click="modalStore.openLoginModal(); closeMobileMenu();">
          {{ languageStore.t('login_register') }}
        </el-button>
      </div>
      
      <!-- 导航菜单 -->
      <div class="mobile-nav-menu">
        <h3 class="menu-title">{{ languageStore.t('menu') }}</h3>
        <el-menu
          class="mobile-menu-list"
          :default-active="activeMenu"
          @select="handleMenuSelect"
        >
          <el-menu-item index="/chat/home">
            <i class="el-icon-s-home"></i>
            <span>{{ languageStore.t('home') }}</span>
          </el-menu-item>
          <el-menu-item index="/chat/about">
            <i class="el-icon-info"></i>
            <span>{{ languageStore.t('about_us') }}</span>
          </el-menu-item>
          <el-menu-item index="/chat/recharge" v-if="isLoggedIn">
            <i class="el-icon-wallet"></i>
            <span>{{ languageStore.t('recharge') }}</span>
          </el-menu-item>
        </el-menu>
      </div>
      
      <!-- 访问历史区域（已登录状态） -->
      <div class="mobile-history-section" v-if="isLoggedIn && recentHistory.length > 0">
        <div class="history-card">
          <div class="card-header">
            <h4>{{ languageStore.t('recent_consultations') }}</h4>
            <button class="view-all-btn" @click="goToUserCenter(); closeMobileMenu();">{{ languageStore.t('view_all') }}</button>
          </div>
          
          <div class="history-list">
            <div 
              v-for="(item, index) in recentHistory.slice(0, 3)" 
              :key="index" 
              class="history-item"
              @click="viewHistoryDetail(item); closeMobileMenu();"
            >
              <div class="history-content">
                <div class="history-title">{{ languageStore.t(item.msg_title) }}</div>
                <div class="history-time">{{ formatTime(item.created_at) }}</div>
              </div>
              <i class="el-icon-arrow-right"></i>
            </div>
          </div>
        </div>
      </div>
      
      <!-- 语言切换区域 -->
      <div class="mobile-language-section">
        <h3 class="lang-section-title">{{ languageStore.t('language') }}</h3>
        <div class="language-options">
          <div 
            v-for="lang in supportedLangs" 
            :key="lang.code" 
            class="language-option" 
            :class="{ 'active': currentLang === lang.code }"
            @click="switchLanguage(lang.code)"
          >
            {{ lang.name }}
          </div>
        </div>
      </div>
    </el-drawer>

    <!-- PC端左侧用户信息栏 -->
    <UserSidebar v-if="!isMobile && isLoggedIn" />
    
    <main class="app-content" :class="{ 'with-sidebar': !isMobile && isLoggedIn }">
      <div class="container">
        <!-- Google广告 - 内容上方 -->
        <div class="ad-container ad-top">
          <!-- 这里放置Google广告代码 -->
        </div>
        <el-config-provider :locale="langObj">
        <router-view :key="query" />
        </el-config-provider>
        
        <!-- Google广告 - 内容下方 -->
        <div class="ad-container ad-bottom">
          <!-- 这里放置Google广告代码 -->
        </div>
      </div>
    </main>

    <footer class="app-footer">
      <div class="container" >
        <div class="footer-content">
          <div class="footer-info">
            <el-space direction="vertical" alignment="start" :size="10">
              <p>&copy; 2025 SpaceTime天纪云国学AI. 保留所有权利</p>
              <el-space alignment="start" :size="10">
                <a href="https://beian.mps.gov.cn/#/query/webSearch?code=2021027762" class="el-link" target="_blank">{{ configObj.wxba }}</a>
                <a href="https://beian.miit.gov.cn/" class="el-link" target="_blank">{{ configObj.icp }}</a>
                <a href="https://beian.miit.gov.cn/" class="el-link" target="_blank">{{ configObj.gaba }}</a>
              </el-space>
            </el-space>
          </div>
        </div>
      </div>
    </footer>
  </div>
  
  <!-- 登录模态框 -->
  <LoginModal v-if="showLoginModal" @close="modalStore.closeLoginModal" @login-success="handleLoginSuccess" />
</template>

<script setup>
import { ref, onMounted, onBeforeUnmount, computed, watch } from 'vue';
import { useRouter } from 'vue-router';
import { storeToRefs } from 'pinia';
import { useUserStore } from '@/store/userStore';
import { useLanguageStore } from '@/store/languageStore';
import { useModalStore } from '@/store/modalStore';
import { getUserInfo, logout } from '@/api/login';
import LoginModal from '@/components/LoginModal.vue';
import UserSidebar from '@/components/UserSidebar.vue';
import { getConfigToObj } from '@/api/config';
import request from '@/utils/request';
import { ElConfigProvider } from 'element-plus'
import zhCn from 'element-plus/es/locale/lang/zh-cn';
import en from 'element-plus/es/locale/lang/en';
import ru from 'element-plus/es/locale/lang/ru';
import ja from 'element-plus/es/locale/lang/ja';

//获取query
const router = useRouter();
const userStore = useUserStore();
const modalStore = useModalStore();
const languageStore = useLanguageStore();
//store转ref
const { showLoginModal } = storeToRefs(modalStore);
const query = router.currentRoute.value.query;
const configObj = ref({});
const langObj = computed(() => {
  switch (languageStore.getCurrentLang) {
    case 'zh-cn':
      return zhCn;
    case 'en-us':
      return en;
    case 'ja-jp':
      return ja;
    case 'be-by':
      return ru;
    default:
      return zhCn;
  }
})
// 默认头像

// 移动菜单状态
const isMobileMenuOpen = ref(false);

// 用户菜单状态
const showUserMenu = ref(false);

// 语言菜单状态
const showLangMenu = ref(false);

// 用户信息
const userInfo = computed(() => userStore.getUserInfo);

// 登录状态
const isLoggedIn = computed(() => userStore.getIsLoggedIn);

// 移动端检测
const isMobile = ref(false);

// 多语言加载状态
const isLanguageReady = ref(false);

// 最近访问历史
const recentHistory = ref([]);

// 检测是否为移动端
const checkMobile = () => {
  isMobile.value = window.innerWidth <= 768;
};

// 切换移动端菜单
const toggleMobileMenu = () => {
  isMobileMenuOpen.value = !isMobileMenuOpen.value;
  
  // 当菜单打开时，禁止页面滚动
  if (isMobileMenuOpen.value) {
    document.body.style.overflow = 'hidden';
  } else {
    document.body.style.overflow = '';
  }
};

// 关闭移动端菜单
const closeMobileMenu = () => {
  isMobileMenuOpen.value = false;
  document.body.style.overflow = '';
};

// 处理头像加载失败
const handleAvatarError = (event) => {
  // 头像加载失败时隐藏img标签，显示文字头像
  event.target.style.display = 'none';
};

// 导航到聊天页面
const navigateToChat = (chatId) => {
  router.push(`/chat/${chatId}`);
};

// 处理菜单项点击
const handleMenuSelect = (index) => {
  router.push(index);
  closeMobileMenu();
};

// 当前激活的菜单项
const activeMenu = computed(() => {
  return router.currentRoute.value.path;
});

// 获取最近的访问历史
const fetchRecentHistory = async () => {
  try {
    const res = await request({
      url: '/v6/user/history',
      method: 'get',
      params: {
        page: 1,
        limit: 5
      }
    });
    
    if (res.code === 0 && res.data) {
      // 只取前5条记录用于移动端菜单显示
      const historyData = res.data.data || [];
      recentHistory.value = historyData.slice(0, 5);
    }
  } catch (error) {
    console.error('获取历史记录失败:', error);
    // 如果API调用失败，使用空数据
    recentHistory.value = [];
  }
};

// 格式化时间
const formatTime = (timestamp) => {
  if (!timestamp) return '';
  
  const date = new Date(timestamp * 1000);
  const now = new Date();
  const diff = Math.floor((now - date) / 1000);
  
  // 如果是今天的时间，显示具体时间
  if (diff < 86400 && date.getDate() === now.getDate()) {
    return `${date.getHours().toString().padStart(2, '0')}:${date.getMinutes().toString().padStart(2, '0')}`;
  }
  
  // 如果是最近7天内，显示周几
  if (diff < 86400 * 7) {
    const days = ['日', '一', '二', '三', '四', '五', '六'];
    return `周${days[date.getDay()]}`;
  }
  
  // 其他情况显示年月日
  return `${date.getFullYear()}-${(date.getMonth() + 1).toString().padStart(2, '0')}-${date.getDate().toString().padStart(2, '0')}`;
};

// 查看历史详情
const viewHistoryDetail = (item) => {
  // 跳转到历史详情页面
  router.push({
    path: '/history-detail',
    query: {
      history_id: item.history_id,
      answer_id: item.answer_id,
      person_menu_id: item.person_menu_id,
      person_menu_item_id: item.person_menu_item_id,
      is_show_time_res: item.is_show_time_res
    }
  });
};

// 切换用户菜单
const toggleUserMenu = () => {
  showUserMenu.value = !showUserMenu.value;
};

// 关闭用户菜单
const closeUserMenu = () => {
  showUserMenu.value = false;
};

// 切换语言菜单
const toggleLangMenu = () => {
  showLangMenu.value = !showLangMenu.value;
};

// 关闭语言菜单
const closeLangMenu = () => {
  showLangMenu.value = false;
};

// 跳转到用户中心
const goToUserCenter = () => {
  router.push('/user-center');
  closeUserMenu();
  closeMobileMenu();
};

// 跳转到充值
const goToRecharge = () => {
  router.push('/chat/recharge');
  closeUserMenu();
  closeMobileMenu();
};

// 处理登录成功
const handleLoginSuccess = (userData) => {
  // 通过 userStore 更新用户状态
  userStore.login(userData);
  // 关闭登录模态框
  modalStore.closeLoginModal();
};

// 处理退出登录
const handleLogout = async () => {
  try {
    await logout();
    // 通过 userStore 清除用户状态
    userStore.logout();
    // 清空历史记录
    recentHistory.value = [];
    // 关闭用户菜单和移动端抽屉
    closeUserMenu();
    closeMobileMenu();
    // 跳转到首页
    router.push({
      name: 'home'
    });
  } catch (error) {
    console.error('退出登录失败:', error);
  }
};

// 点击其他区域关闭用户菜单和语言菜单
const handleClickOutside = (event) => {
  const userDropdown = document.querySelector('.user-dropdown');
  const userMenu = document.querySelector('.user-menu');
  const langSwitcher = document.querySelector('.language-switcher');
  
  if (userDropdown && !userDropdown.contains(event.target) && 
      userMenu && !userMenu.contains(event.target)) {
    closeUserMenu();
  }
  
  if (langSwitcher && !langSwitcher.contains(event.target)) {
    closeLangMenu();
  }
};

// 多语言相关
// 当前语言代码
const currentLang = computed(() => languageStore.getCurrentLang);
// 支持的语言列表
const supportedLangs = computed(() => languageStore.getSupportedLangs);
// 当前语言名称
const currentLangName = computed(() => {
  const lang = supportedLangs.value.find(l => l.code === currentLang.value);
  return lang ? lang.name : '中文';
});

// 切换语言
const switchLanguage = async (langCode) => {
  await languageStore.switchLanguage(langCode);
  closeLangMenu();
};

// 检测是否从微信授权返回
const checkWechatLoginReturn = () => {
  const isPending = sessionStorage.getItem('wechat_login_pending')
  const loginTime = sessionStorage.getItem('wechat_login_time')
  const wechatState = sessionStorage.getItem('wechat_login_state')
  
  console.log('MainLayout检测微信授权返回:', { 
    isPending, 
    loginTime, 
    wechatState,
    hasUser: !!userStore.userInfo 
  })
  
  if (isPending && loginTime && wechatState) {
    const timeDiff = Date.now() - parseInt(loginTime)
    // 如果是5分钟内从微信授权返回，自动打开登录弹窗以触发轮询
    if (timeDiff < 5 * 60 * 1000) {
      console.log('✅ 检测到微信授权返回，自动打开登录弹窗')
      // 立即打开登录弹窗
      modalStore.openLoginModal()
    } else {
      console.log('❌ 微信授权已超时，清理数据')
      sessionStorage.removeItem('wechat_login_pending')
      sessionStorage.removeItem('wechat_login_time')
      sessionStorage.removeItem('wechat_login_state')
    }
  }
}

// 在布局加载时获取全局配置
onMounted(async () => {
  // 延迟检测微信授权返回，确保DOM完全加载
  setTimeout(() => {
    checkWechatLoginReturn()
  }, 100)
  try {
    console.log('开始初始化应用...');
    
    // 首先初始化多语言，完成后再显示页面
    await languageStore.initLanguage();
    console.log('多语言初始化完成');
    
    // 多语言加载完成，可以显示页面
    isLanguageReady.value = true;
    
    // 检测移动端
    checkMobile();
    
    // 如果已登录，获取用户信息
    if (isLoggedIn.value) {
      const userData = getUserInfo();
      if (userData) {
        userStore.setUserInfo(userData);
      }
    }
    
    // 添加点击其他区域关闭用户菜单的事件监听
    document.addEventListener('click', handleClickOutside);

    // 获取系统配置
    const res = await getConfigToObj();
    configObj.value = res.data;
    
    console.log('应用初始化完成');
  } catch (error) {
    console.error('应用初始化失败:', error);
    // 即使失败也显示页面，避免白屏
    isLanguageReady.value = true;
  }
});

// 监听窗口大小变化，在桌面模式下关闭可能打开的移动菜单
const handleResize = () => {
  checkMobile();
  if (window.innerWidth >= 768 && isMobileMenuOpen.value) {
    closeMobileMenu();
  }
};

// 组件挂载时添加事件监听
onMounted(() => {
  window.addEventListener('resize', handleResize);
  
  // 如果已登录，获取最近访问历史
  if (isLoggedIn.value) {
    fetchRecentHistory();
  }
});

// 监听登录状态变化
watch(isLoggedIn, (newValue) => {
  if (newValue) {
    // 用户登录时获取最近访问历史
    fetchRecentHistory();
  } else {
    // 用户退出登录时清空数据
    recentHistory.value = [];
  }
});

// 组件卸载时移除事件监听
onBeforeUnmount(() => {
  window.removeEventListener('resize', handleResize);
  document.removeEventListener('click', handleClickOutside);
});
</script>

<style lang="less" scoped>
@import "@/assets/styles/variables.less";

// 响应式断点
@mobile: ~"(max-width: 767px)";
@tablet: ~"(min-width: 768px) and (max-width: 1023px)";
@desktop: ~"(min-width: 1024px)";

.app-layout {
  width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: linear-gradient(to bottom, #e6e6fa 0%, #ffffff 50%, #ffffff 100%);
}

.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 15px;
  
  @media @mobile {
    padding: 0 10px;
  }
}

// 头部样式
.app-header {
  background-color: #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  position: sticky;
  top: 0;
  z-index: 100;
  
  .header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 70px;
    
    @media @mobile {
      height: 60px;
    }
  }
  
  .logo {
    display: flex;
    align-items: center;
    
    img {
      height: 66px;
      margin-right: 10px;
      
      @media @mobile {
        height: 60px;
      }
    }
    
    h1 {
      font-size: 20px;
      margin: 0;
      color: #333;
      
      @media @mobile {
        font-size: 18px;
      }
    }
  }
  
  .desktop-nav {
    @media @mobile {
      display: none;
    }
    
    .nav-links {
      display: flex;
      list-style: none;
      margin: 0;
      padding: 0;
      
      li {
        margin-left: 25px;
        
        a {
          color: #555;
          text-decoration: none;
          font-size: 16px;
          transition: color 0.3s;
          
          &:hover, &.router-link-active {
            color: @primary-color;
          }
        }
      }
    }
  }
  
  // 语言切换器样式
  .language-switcher {
    display: flex;
    align-items: center;
    position: relative;
    margin-left: 15px;
    
    .selected-lang {
      display: flex;
      align-items: center;
      cursor: pointer;
      padding: 5px 10px;
      border-radius: 4px;
      background-color: #f5f5f5;
      transition: background-color 0.3s;
      
      &:hover {
        background-color: #e8e8e8;
      }
      
      span {
        margin-right: 5px;
      }
      
      .lang-arrow {
        font-size: 10px;
        color: #666;
      }
    }
    
    .lang-menu {
      position: absolute;
      top: 35px;
      right: 0;
      background-color: white;
      border-radius: 4px;
      box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
      min-width: 120px;
      z-index: 101;
      
      .lang-item {
        padding: 10px 15px;
        cursor: pointer;
        transition: background-color 0.3s;
        
        &:hover {
          background-color: #f5f5f5;
        }
        
        &.active {
          color: @primary-color;
          font-weight: bold;
        }
      }
    }
    
    @media @mobile {
      display: none;
    }
  }
  
  // 用户区域样式
  .user-area {
    display: flex;
    align-items: center;
    margin-left: 20px;
    position: relative;
    
    @media @mobile {
      display: none;
    }
    
    .login-btn {
      background-color: @primary-color;
      color: white;
      border: none;
      border-radius: 4px;
      padding: 8px 16px;
      font-size: 14px;
      cursor: pointer;
      transition: background-color 0.3s;
      
      &:hover {
        background-color: darken(@primary-color, 10%);
      }
    }
    
    .user-dropdown {
      display: flex;
      align-items: center;
      cursor: pointer;
      padding: 5px 10px;
      border-radius: 20px;
      transition: background-color 0.3s;
      
      &:hover {
        background-color: #f5f5f5;
      }
      
      .username {
        margin-right: 10px;
        max-width: 100px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
      
      .user-avatar {
        width: 32px;
        height: 32px;
        border-radius: 50%;
        overflow: hidden;
        
        img {
          width: 100%;
          height: 100%;
          object-fit: cover;
        }
      }
    }
    
    .user-menu {
      position: absolute;
      top: 45px;
      right: 0;
      width: 120px;
      background-color: white;
      box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
      border-radius: 4px;
      z-index: 101;
      overflow: hidden;
      
      .user-menu-item {
        padding: 10px 15px;
        cursor: pointer;
        transition: background-color 0.2s;
        
        &:hover {
          background-color: #f5f5f5;
        }
      }
    }
  }
  
  .mobile-menu-toggle {
    display: none;
    flex-direction: column;
    justify-content: space-between;
    width: 24px;
    height: 20px;
    cursor: pointer;
    
    @media @mobile {
      display: flex;
    }
    
    span {
      display: block;
      width: 100%;
      height: 3px;
      background-color: #333;
      border-radius: 3px;
      transition: all 0.3s;
    }
    
    &:hover span {
      background-color: @primary-color;
    }
  }
  
  .lang-menu {
    position: absolute;
    top: 35px;
    right: 0;
    background-color: white;
    border-radius: 4px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    min-width: 120px;
    z-index: 101;
    
    .lang-item {
      padding: 10px 15px;
      cursor: pointer;
      transition: background-color 0.3s;
      
      &:hover {
        background-color: #f5f5f5;
      }
      
      &.active {
        color: @primary-color;
        font-weight: bold;
      }
    }
  }
}

// 用户区域样式
.user-area {
  display: flex;
  align-items: center;
  margin-left: 20px;
  position: relative;
  
  @media @mobile {
    display: none;
  }
  
  .login-btn {
    background-color: @primary-color;
    color: white;
    border: none;
    border-radius: 4px;
    padding: 8px 16px;
    font-size: 14px;
    cursor: pointer;
    transition: background-color 0.3s;
    
    &:hover {
      background-color: darken(@primary-color, 10%);
    }
  }
  
  .user-dropdown {
    display: flex;
    align-items: center;
    cursor: pointer;
    padding: 5px 10px;
    border-radius: 20px;
    transition: background-color 0.3s;
    
    &:hover {
      background-color: #f5f5f5;
    }
    
    .username {
      margin-right: 10px;
      max-width: 100px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
    
    .user-avatar {
      width: 32px;
      height: 32px;
      border-radius: 50%;
      overflow: hidden;
      
      img {
        width: 100%;
        height: 100%;
        object-fit: cover;
      }
    }
  }
  
  .user-menu {
    position: absolute;
    top: 45px;
    right: 0;
    width: 120px;
    background-color: white;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    z-index: 101;
    overflow: hidden;
    
    .user-menu-item {
      padding: 10px 15px;
      cursor: pointer;
      transition: background-color 0.2s;
      
      &:hover {
        background-color: #f5f5f5;
      }
    }
  }
}

.mobile-menu-toggle {
  display: none;
  flex-direction: column;
  justify-content: space-between;
  width: 24px;
  height: 20px;
  cursor: pointer;
  
  @media @mobile {
    display: flex;
  }
  
  span {
    display: block;
    width: 100%;
    height: 3px;
    background-color: #333;
    border-radius: 3px;
    transition: all 0.3s;
  }
  
  &:hover span {
    background-color: @primary-color;
  }
}

// 移动端抽屉菜单样式
:deep(.mobile-drawer) {
  background-color: #ffffff;
  color: #333;
  
  .el-drawer__body {
    padding: 0;
    overflow-y: auto;
  }
  
  .el-drawer__header {
    background-color: #4169E1;
    margin-bottom: 0;
    padding: 15px;
    border-bottom: 1px solid #e8f0fe;
  }
}

// 用户信息卡片样式
.mobile-user-profile {
  padding: 20px;
  background: linear-gradient(135deg, #e8f0fe, #f8f9ff);
  border-radius: 0 0 12px 12px;
  margin-bottom: 20px;
  box-shadow: 0 3px 10px rgba(65, 105, 225, 0.1);
  
  .user-profile-card {
    .user-avatar-section {
      display: flex;
      align-items: center;
      
      .user-avatar-container {
        margin-right: 15px;
        
        .user-avatar-img {
          width: 60px;
          height: 60px;
          border-radius: 50%;
          overflow: hidden;
          background-color: #ffffff;
          display: flex;
          align-items: center;
          justify-content: center;
          box-shadow: 0 2px 8px rgba(65, 105, 225, 0.2);
          border: 2px solid #4169E1;
          
          img {
            width: 100%;
            height: 100%;
            object-fit: cover;
          }
        }
      }
      
      .user-basic-info {
        flex: 1;
        
        .username {
          margin: 0 0 5px;
          font-size: 18px;
          color: #333;
          font-weight: 600;
        }
        
        .user-status {
          display: flex;
          align-items: center;
          margin: 0 0 5px;
          color: #4169E1;
          font-size: 14px;
          font-weight: 500;
          
          .premium-icon {
            margin-right: 5px;
          }
        }
        
        .user-phone {
          margin: 0;
          font-size: 14px;
          color: #666;
        }
      }
    }
  }
  
  // 快捷操作按钮
  .quick-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 15px;
    
    .action-btn {
      width: 100%;
      display: flex;
      flex-direction: row;
      align-items: center;
      justify-content: flex-start;
      padding: 12px 15px;
      background-color: #ffffff;
      border: 1px solid #e8e8e8;
      border-radius: 8px;
      color: #666;
      font-size: 14px;
      cursor: pointer;
      transition: all 0.3s ease;
      box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
      
      &:hover {
        background-color: #e8f0fe;
        transform: translateY(-2px);
        color: #4169E1;
        box-shadow: 0 4px 8px rgba(65, 105, 225, 0.15);
      }
      
      .icon {
        font-size: 20px;
        margin-right: 12px;
        color: #4169E1;
        line-height: 1;
      }
      
      &.logout-btn {
        background-color: #fff;
        color: #666;
        
        &:hover {
          background-color: #ffebee;
          color: #dc3545;
          
          .icon {
            color: #dc3545;
          }
        }
      }
    }
  }
}

// 未登录状态登录按钮
.mobile-login-section {
  padding: 30px 20px;
  text-align: center;
  
  .mobile-login-btn {
    width: 80%;
    height: 44px;
    font-size: 16px;
  }
}

// 导航菜单样式
.mobile-nav-menu {
  padding: 0 15px 20px;
  
  .menu-title {
    font-size: 16px;
    font-weight: 600;
    color: #4169E1;
    margin: 0 0 15px 5px;
    padding-bottom: 10px;
    border-bottom: 1px solid #e8f0fe;
    text-align: center;
  }
  
  .mobile-menu-list {
    border-radius: 10px;
    overflow: hidden;
    background-color: #f8f9ff;
    border: none;
    box-shadow: 0 2px 10px rgba(65, 105, 225, 0.1);
    
    :deep(.el-menu-item) {
      height: 50px;
      line-height: 50px;
      color: #666;
      background-color: #ffffff;
      margin-bottom: 8px;
      border-radius: 8px;
      font-weight: 500;
      
      &:hover {
        background-color: #e8f0fe;
        color: #4169E1;
      }
      
      &.is-active {
        color: #fff;
        background-color: #4169E1;
        box-shadow: 0 4px 8px rgba(65, 105, 225, 0.25);
      }
      
      i {
        color: #4169E1;
        margin-right: 10px;
        margin-right: 12px;
        font-size: 18px;
      }
    }
  }
}

// 访问历史区域样式
.mobile-history-section {
  padding: 0 15px 20px;
  
  .history-card {
    background-color: #f8f9ff;
    border-radius: 10px;
    padding: 15px;
    box-shadow: 0 3px 8px rgba(65, 105, 225, 0.1);
    
    .card-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 15px;
      
      h4 {
        margin: 0;
        font-size: 16px;
        color: #4169E1;
        font-weight: 600;
      }
      
      .view-all-btn {
        background: none;
        border: none;
        color: #4169E1;
        font-size: 14px;
        cursor: pointer;
        padding: 0;
        font-weight: 500;
      }
    }
    
    .history-list {
      .history-item {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 12px;
        background-color: #ffffff;
        border-radius: 8px;
        margin-bottom: 10px;
        cursor: pointer;
        transition: all 0.3s ease;
        border-left: 3px solid transparent;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);

        
        &:last-child {
          margin-bottom: 0;
        }
        
        &:hover {
          background-color: #e8f0fe;
          border-left: 3px solid #4169E1;
          transform: translateX(2px);
        }
        
        .history-content {
          flex: 1;
          overflow: hidden;
          .history-title {
            font-size: 14px;
            color: #333;
            margin-bottom: 5px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            font-weight: 500;
            
          }
          
          .history-time {
            font-size: 12px;
            color: #888;
          }
        }
        
        i {
          color: #4169E1;
          font-size: 16px;
        }
      }
    }
  }
}

// 语言切换区域样式
.mobile-language-section {
  padding: 0 15px 20px;
  
  .lang-section-title {
    font-size: 16px;
    font-weight: 600;
    color: #4169E1;
    margin: 0 0 15px 5px;
    padding-bottom: 10px;
    border-bottom: 1px solid #e8f0fe;
    text-align: center;
  }
  
  .language-options {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    background-color: #f8f9ff;
    border-radius: 10px;
    padding: 15px;
    box-shadow: 0 2px 10px rgba(65, 105, 225, 0.1);
    
    .language-option {
      flex: 1;
      min-width: 80px;
      padding: 10px 15px;
      background-color: #ffffff;
      border-radius: 8px;
      color: #666;
      cursor: pointer;
      transition: all 0.3s ease;
      box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
      border: 1px solid #e8e8e8;
      font-weight: 500;
      text-align: center;
      
      &:hover {
        background-color: #e8f0fe;
        transform: translateY(-2px);
        box-shadow: 0 4px 8px rgba(65, 105, 225, 0.15);
        color: #4169E1;
      }
      
      &.active {
        background-color: #4169E1;
        color: white;
        border: 1px solid #4169E1;
        box-shadow: 0 4px 8px rgba(65, 105, 225, 0.25);
      }
    }
  }
}

// 主内容区域
.app-content {
  flex: 1;
  padding: 20px 0;
  min-height: calc(100vh - 120px);
  
  &.with-sidebar {
    margin-left: 280px;
    
    @media (max-width: 768px) {
      margin-left: 0;
    }
  }
}

// 底部样式
.app-footer {
  background-color: #f8f9fa;
  padding: 25px 0;
  margin-top: auto;
  
  .footer-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    
    @media @mobile {
      flex-direction: column;
      text-align: center;
    }
  }
  
  .footer-info {
    width: 100%;
    text-align: center;
    
    p {
      margin: 0;
      color: #666;
      font-size: 14px;
      
      @media @mobile {
        font-size: 13px;
        margin-bottom: 10px;
        line-height: 1.4;
      }
    }
    
    .el-space {
      @media @mobile {
        .el-space__item {
          margin-bottom: 4px !important;
        }
      }
    }
    
    // 移动端备案链接样式优化
    @media @mobile {
      .el-space--horizontal {
        flex-direction: column;
        align-items: center;
        
        .el-space__item {
          margin-right: 0 !important;
          margin-bottom: 6px;
          
          &:last-child {
            margin-bottom: 0;
          }
          
          .el-link {
            font-size: 12px;
            padding: 4px 6px;
            line-height: 1.3;
            word-break: keep-all;
            white-space: nowrap;
            display: inline-block;
          }
        }
      }
    }
  }
  
  .footer-links {
    display: flex;
    
    @media @mobile {
      margin-top: 15px;
    }
    
    a {
      color: #666;
      text-decoration: none;
      margin-left: 20px;
      
      &:first-child {
        margin-left: 0;
      }
      
      &:hover {
        color: @primary-color;
      }
    }
  }
}

// 多语言加载状态样式
.language-loading {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  background-color: #fff;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  
  .loading-content {
    text-align: center;
    
    .loading-spinner {
      width: 40px;
      height: 40px;
      border: 4px solid #f3f3f3;
      border-top: 4px solid @primary-color;
      border-radius: 50%;
      animation: spin 1s linear infinite;
      margin: 0 auto 20px;
    }
    
    p {
      color: #666;
      font-size: 16px;
      margin: 0;
    }
  }
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
</style>
